#!/usr/bin/env python3
import argparse
from config import attr
from get_point import gen_points
from get_point import setLogging
from get_point import Links_stack
from get_point import get_headers

def get_args():
    doc = """
    this is script dir all links in site , 
    and classify out link or other links, 
    or find some special links and so on
    --- write by qingluan
    """
    parser = argparse.ArgumentParser(usage=" how to use this "
        , description=doc)
    parser.add_argument("-u", "--scan-url", default='', help="this can scan all link and classify ")
    parser.add_argument("-o", "--output", default='', help="special ouput to a file")
    parser.add_argument("-H", "--headers", default='', help="set headers for this")
    parser.add_argument("--cookie-url",default='', help="special a url to got a cookie")
    return parser.parse_args()

def main():
    args = get_args()
    headers = None
    if args.scan_url:

        print("scan " + args.scan_url)
        if args.output:
            print("log to " + args.output)
            setLogging(file_name=args.output)
        
        
        headers = get_headers(args.scan_url.split('//')[1], text=args.headers)
        Links_stack.set_headers(headers)
        if args.cookie_url:
            Links_stack.init_session(args.cookie_url)

        count = 1
        if Links_stack.session:
            print("init cookie ")
        for i in gen_points(args.scan_url, args.scan_url):
            print(attr.green % "=> [%d]" % count,end="\r")
            count += 1

if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt as e:
        print("\nbye bye~ nice day")